//
//  NextViewController.m
//  dispatch_group
//
//  Created by 梁森 on 17/7/14.
//  Copyright © 2017年 梁森. All rights reserved.
//

#import "NextViewController.h"

@interface NextViewController ()

@end

@implementation NextViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    
    dispatch_group_t group = dispatch_group_create();
    dispatch_queue_t serialQueue = dispatch_queue_create("com.wzb.test.www", DISPATCH_QUEUE_SERIAL);
    dispatch_group_enter(group);
    dispatch_group_async(group, serialQueue, ^{
        // 网络请求一
//        [WebClick getDataSuccess:^(ResponseModel *model) {
//            dispatch_group_leave(group);
//        } failure:^(NSString *err) {
//            dispatch_group_leave(group);
//        }];
    });
    dispatch_group_enter(group);
    dispatch_group_async(group, serialQueue, ^{
        // 网络请求二
//        [WebClick getDataSuccess:getBigTypeRM onSuccess:^(ResponseModel *model) {
//            dispatch_group_leave(group);
//        }                                  failure:^(NSString *errorString) {
//            dispatch_group_leave(group);
//        }];
    });
    dispatch_group_enter(group);
    dispatch_group_async(group, serialQueue, ^{
        // 网络请求三
//        [WebClick getDataSuccess:^{
//            dispatch_group_leave(group);
//        } failure:^(NSString *errorString) {
//            dispatch_group_leave(group);
//        }];
    });
    
    // 所有网络请求结束后会来到这个方法
    dispatch_group_notify(group, serialQueue, ^{
        dispatch_async(dispatch_get_global_queue(0, 0), ^{
            dispatch_async(dispatch_get_main_queue(), ^{
                // 刷新UI
            });
        });
    });
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
